package com.able.concurrency.t1;

/**
 * @author abel.he
 * @data 2018/8/15 20:00
 * @describe 常量问题：在定义代码块时，不要使用常量对象作为锁对象
 */
public class Test14 {

    String s1 = "hello word";
    String s2 = "hello word";

    void m1() {
        synchronized (s1) {
            System.out.println("m1");
            while (true) {

            }
        }
    }

    void m2() {
        synchronized (s2) {
            System.out.println("m2");
            while (true) {

            }
        }
    }

    public static void main(String[] args) {
        final Test14 test14 = new Test14();
        new Thread(new Runnable() {
            public void run() {
                test14.m1();
            }
        }).start();
        new Thread(new Runnable() {
            public void run() {
                test14.m2();
            }
        }).start();
    }

}
